package com.yanqu.road.server.cmd.activity.shuihuyezicard;

import com.yanqu.road.pb.activity.ShuiHuYeZiCardProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.shuihuyezicard.ShuiHuYeZiCardMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @Description
 * @Author cwq
 * @Data 2021/12/30 10:00
 */
@Cmd(code = GameProtocol.S_SHUIHUYEZICARD_PVP_MATCH_OVER_TIME_FROM_CROSS, desc = "水浒叶子牌 超时匹配 跨服返回区服 协议")
public class ShuiHuYeZiCardMatchOverTimeFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(packet.getPlayerId());
        if(player != null){
            ShuiHuYeZiCardProto.ShuiHuYeZiCardMatchOverTimeCrossToGameMsg crossMsg = ShuiHuYeZiCardProto.ShuiHuYeZiCardMatchOverTimeCrossToGameMsg.parseFrom(packet.getBytes());
            ShuiHuYeZiCardMgr.cancelMatch(player,crossMsg.getRoomId());

            ShuiHuYeZiCardProto.BroadcastShuiHuYeZiCardRespMsg.Builder broadcast = ShuiHuYeZiCardProto.BroadcastShuiHuYeZiCardRespMsg.newBuilder();
            broadcast.setType(4);
            player.sendPacket(ClientProtocol.U_SHUIHUYEZICARD_BROADCAST,broadcast);
        }
    }
}
